﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoredLis练习
{
    class Program
    {
        static void Main(string[] args)
        {
            //SortedList sortedList = new SortedList();
            //sortedList.Add(1,"张三");
            //sortedList.Add(2,"李四");
            //sortedList.Add(3,"王五");
            //Console.WriteLine("请输入挂号编号");
            //int Id = int.Parse(Console.ReadLine());
            //bool flag = sortedList.ContainsKey(Id);
            //if (flag)
            //{
            //    string name = sortedList[Id].ToString();
            //    Console.WriteLine("你查询的患者名字为：{0}",name);
            //}
            //else
            //{
            //    Console.WriteLine("你查询的患者并不存在或者已经出院");
            //}
            //Console.WriteLine("所有的挂号编号信息如下");
            //foreach (DictionaryEntry item in sortedList)
            //{
            //    int key = (int)item.Key;
            //    string value = item.Value.ToString();
            //    Console.WriteLine("编号为：{0}，患者姓名为:{1}",key,value);
            //}
            //Console.ReadKey();


            SortedList sortedList = new SortedList();
            sortedList.Add(1, "张三");
            sortedList.Add(2, "李四");
            sortedList.Add(3, "王五");       //向集合里面添加元素
            Console.WriteLine("请输入你要查询的编号");
            int Id = int.Parse(Console.ReadLine());
            bool flag = sortedList.ContainsKey(Id);     //查询集合里是否包含这个键并赋值给布尔变量flag
            if (flag)
            {
                string name =sortedList[Id].ToString(); //将键值对转换为字符串
                Console.WriteLine("你查找的患者姓名为：{0}",name);
            }
            else
            {
                Console.WriteLine("你查找的患者不存在，或者可能已经出院了");
            }
            Console.WriteLine("挂号编号信息如下");
            foreach (DictionaryEntry item in sortedList)
            {
                int key = (int)item.Key;    //里氏转换
                string value = (string)item.Value;  //里氏转换
                Console.WriteLine("编号为：{0}的患者名字为：{1}", key,value);
            }
            Console.ReadKey();
        }
    }
}
